package jmine.tec.web.wicket.security;

import javax.security.auth.Subject;

import jmine.tec.web.wicket.spring.SpringBeanReference;

import org.apache.wicket.Request;
import org.apache.wicket.protocol.http.WebSession;

import bancosys.tec.security.SecurityManager;

/**
 * @author takeshi
 */
public class SecureSession extends WebSession {

    private volatile Subject subject;

    private transient SecurityManager securityManager;

    /**
     * C'tor
     * 
     * @param request o {@link Request}
     */
    public SecureSession(Request request) {
        super(request);
    }

    /**
     * @return the subject
     */
    public Subject getSubject() {
        return this.subject;
    }

    /**
     * @param subject the logged to set
     */
    public void setSubject(Subject subject) {
        this.subject = subject;
    }

    /**
     * @return {@link SecureSession}
     */
    public static SecureSession getSecureSession() {
        return (SecureSession) get();
    }

    /**
     * @return the securityManager
     */
    public SecurityManager getSecurityManager() {
        if (this.securityManager == null) {
            this.securityManager = SpringBeanReference.forType(SecurityManager.class).get();
        }
        return this.securityManager;
    }

    /**
     * @param securityManager the securityManager to set
     */
    public void setSecurityManager(SecurityManager securityManager) {
        this.securityManager = securityManager;
    }
}
